use crate::cmd_result::CmdResult;
use crate::service::connection::ConnectService as C;
use crate::db::real_time_db::RealTimeDatabase as db;

#[derive(serde::Deserialize, Debug)]
pub enum ActionType {
    SaveConnect,
    AllConnect,
    OpenConnect,
    DeleteConnect,
    HelloDB,
    TablesByDb,
    GenerateSdkTags
}

pub async fn execute(action: ActionType, json: String) -> anyhow::Result<CmdResult> {
    return match action {
        ActionType::SaveConnect => C::json(json).save(),
        ActionType::AllConnect => C::json(String::new()).get_all(),
        ActionType::OpenConnect => db::json(json).find_db_by_connect().await,
        ActionType::DeleteConnect => C::json(json).delete(),
        ActionType::HelloDB => db::json(json).hello().await,
        ActionType::TablesByDb => db::json(json).tables_by_db().await,
        ActionType::GenerateSdkTags => db::json(json).generate_sdk_tags().await
    };
}
